package engine;

import java.util.ArrayList;
import java.util.List;

import com.sampullara.poker.Cards;
import com.sampullara.poker.Evaluate;

public class Evaluator {
	public Evaluator(){
		
	}
	
	public void evaluateHands(List<Player> players, List<Card>  board){
		for (int i = 0; i < players.size(); i++) {
			Hand hand = players.get(i).hand;
			String handShort = "";
			String boardShort = "";
			for (int i1 = 0; i1 < 2; i1++) {
				handShort += "" + hand.cards.get(i1).getRank().charAt(0) +""+ hand.cards.get(i1).getSuit().toLowerCase().charAt(0);
			}
			for (int i1 = 0; i1 < board.size(); i1++) {
				boardShort += "" + board.get(i1).getRank().charAt(0) +""+ board.get(i1).getSuit().toLowerCase().charAt(0);
			}
			System.out.println(handShort);
			Cards handCards = new Cards(handShort);
			Cards boardCards = new Cards(boardShort);
			players.get(i).hand.setRank(Evaluate.holdem(handCards, boardCards));
		}
	}
	
	public List<Player> getWinners(List<Player> players){
		List<Player> winners = new ArrayList<Player>();
		Player best = players.get(0);
		winners.add(best);
		for (int i = 1; i < players.size(); i++) {
			int tmp = best.hand.getRank().compareTo(players.get(i).hand.getRank());
			if (tmp < 0){
				winners = new ArrayList<Player>();
				best = players.get(i);
				winners.add(best);
			}
			else if (tmp == 0){
				winners.add(players.get(i));
			}
		}
		return winners;
	}
}
